<template>
  <div>
    <!-- 表格操作项 start  -->
    <template v-for="(item, index) in tableBtn">
      <Button
        v-if="showBtn(item.label)"
        :key="index"
        type="primary"
        :icon="item.icon"
        class="ivu-mr-8"
        @click="tableTopOperate(item.name)"
        >{{ item.label }}</Button
      >
    </template>
    <!-- 选择批量新增模板 -->
    <batch-maintain-dialog :visible.sync="addModel"></batch-maintain-dialog>
  </div>
</template>
<script>
import dynamictablebtns from '@/mixins/dynamictablebtns'; // 混入通用代码
import { mapGetters } from 'vuex';
import { getBtnsId } from '@/libs/btnsPermission';
import batchMaintainDialog from '@/components/common/dialog/batchMaintainDialog';
export default {
  mixins: [dynamictablebtns],
  components: { batchMaintainDialog },
  data () {
    return {
      addModel: false
    };
  },
  computed: {
    ...mapGetters('permissions/systemBtns', ['showBtn'])
  },
  methods: {
    tableTopOperate (name) {
      if (name === 'batchAdd') {
        // 批量新增
        let curBtnId = getBtnsId('批量新增');
        sessionStorage.setItem('buttonId', curBtnId);
        this.addModel = true;
      } else {
        let curBtnId = getBtnsId('新增');
        sessionStorage.setItem('buttonId', curBtnId);
        this.$router.push({
          path: '/commodity/commodityAccessManage/addCommodity/commodityAdd',
          query: {}
        });
      }
    },
  }
};
</script>
